<?php
//php测试性能代码
function echotime($name)
{
    static $t_start = 0;
    $t_end = microtime(true);
    if ($name != 'start') {
		echo $name , ':', $t_end - $t_start ," s\r\n";
    }
    $t_start = $t_end;
}


$starttime=microtime(true);
$loop = 10000;
$array = array();
echotime('start');
for ($i = 0; $i < $loop; $i ++) {
    $array['abc' . $i] = 'abc' . $i;
}
echotime('array');
for ($i = 0; $i < $loop; $i ++) {
    if (array_key_exists('abc' . $i, $array)) {
        $a = true;
    }
}
echotime('array_key_exists');
for ($i = 0; $i < $loop; $i ++) {
    if (isset($array['abc' . $i])) {
        $a = true;
    }
}
echotime('isset');
for ($i = 0; $i < $loop; $i ++) {
    if (in_array('abc' . $i, $array)) {
        $a = true;
    }
}
echotime('in_array');
for ($i = 0; $i < $loop; $i ++) {
    if (array_search('abc' . $i, $array)) {
        $a = true;
    }
}
echotime('array_search');
$array2 = array_flip($array);
for ($i = 0; $i < $loop; $i ++) {
    if (isset($array2['abc' . $i])) {
        $a = true;
    }
}
echotime('flip and search');
$array2 = $array;
foreach ($array2 as $k => $v) {
    $array2[$k] = strtoupper($v);
}
echotime('strtoupper');
$array2 = $array;
foreach ($array2 as &$v) {
    $v = strtoupper($v);
}
echotime('strtoupper2');
$array2 = $array;
$array2 = array_map('strtoupper', $array2);
echotime('array_map');

echo "Static Time:  " , (microtime(true)-$starttime) ," s\r\n";
